package cn.lg.soar.system.auth.model;

import cn.lg.soar.system.auth.entity.Org;
import cn.lg.soar.system.auth.entity.User;
import cn.lg.soar.system.general.entity.UserTag;
import cn.lg.soar.system.auth.enums.UserSelectorTypeEnum;
import lombok.Getter;
import lombok.Setter;

/**
 * @author luguoxiang
 * @date 2022/6/13
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
public class UserSelectorDTO {

    private Long id;

    private String name;

    private Object other;

    private UserSelectorTypeEnum type;

    private String avatar;

    private Integer descendantQuantity;

    public static UserSelectorDTO from(User user) {
        if (user == null) {
            return null;
        }
        UserSelectorDTO dto = new UserSelectorDTO();
        dto.id = user.getId();
        dto.name = user.getNickname();
        dto.type = UserSelectorTypeEnum.USER;
        dto.other = user.getUsername();
        dto.avatar = user.getAvatar();
        return dto;
    }

    public static UserSelectorDTO from(Org org) {
        if (org == null) {
            return null;
        }
        UserSelectorDTO dto = new UserSelectorDTO();
        dto.id = org.getId();
        dto.name = org.getName();
        dto.type = UserSelectorTypeEnum.ORG;
        dto.other = org.getType();
        return dto;
    }

    public static UserSelectorDTO from(UserTag tag) {
        if (tag == null) {
            return null;
        }
        UserSelectorDTO dto = new UserSelectorDTO();
        dto.id = tag.getId();
        dto.name = tag.getName();
        dto.type = UserSelectorTypeEnum.TAG;
        return dto;
    }


}
